/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * <p>Project: jse2302 - Server
 * <p>Powered by webrx On 2023-06-30 14:05:46
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Server {
    public static void main(String[] args) {
        try(var server = new ServerSocket(1212)){
            System.out.println("服务器:192.168.11.44，端口号:1212 running....");
            Socket s = server.accept();

            while(true) {
                //接收s.getInputStream();
                BufferedReader read = new BufferedReader(new InputStreamReader(s.getInputStream()));
                System.out.println(read.readLine());

                //发送s.getOutputStream();
                PrintWriter out = new PrintWriter(s.getOutputStream());
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入信息：");
                String msg = sc.nextLine() + "\r\n";
                out.write(msg);
                out.flush();
            }


        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void temp(String[] args) {
        //server ip  localhost 127.0.0.1 192.168.11.44

        List<ServerSocket> ss = new ArrayList<>();
        while (true) {
            try (var s = new ServerSocket(6666)) {
                s.accept(); //中断
                System.out.println("有人访问");
                ss.add(s);
            } catch (Exception e) {
            }
        }
    }
}
